const db = require("../db/index");
// 导入jwt，用于生成token
const jwt = require("jsonwebtoken");
// 导入jwt配置文件 用于加密跟解密
const jwtconfig = require("../jwt_config/index.js");

exports.getVirualList = (req, res) => {
  const sql = "select * from test";
  db.query(sql, (err, results) => {
    if (err) {
      return res.cc(err);
    }
    res.send({
      status: 0,
      result: results,
    });
  });
};
// 不同身份  对应的不同路由权限
const userRoute = "user";
const productRoute = "product";
const doctorRoute = "doctor";
exports.getRoute = (req, res) => {
  const token = req.headers.authorization;
  const tokens = token.split(" ")[1];
  const decoded = jwt.decode(tokens);
  let identity = decoded.identity;
  let identityRoute = null;
  if (identity == "用户") {
    identityRoute = userRoute;
  } else if (identity == "产品经理") {
    identityRoute = productRoute;
  } else {
    identityRoute = doctorRoute;
  }
  res.send({
    status: 0,
    identityRoute: identityRoute,
  });
};

exports.getUserinfo = (req, res) => {
  const token = req.headers.authorization;
  const tokens = token.split(" ")[1];
  const decoded = jwt.decode(tokens);
  res.send({
    status: 0,
    data: decoded,
  });
};
